<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>角色新增/编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">

</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="padding-top: 5px;border: hidden">
    <form class="layui-form" action="" lay-filter="dataForm">
        <div class="layui-form-item layui-col-md11 layui-col-sm11">
            <label class="layui-form-label">角色ID</label>
            <div class="layui-input-block">
                <input type="text" id="ipt_roleId" name="roleId"  readonly class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-col-md11 layui-col-sm11">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-block">
                <input type="text" name="roleName" readonly                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-col-md11 layui-col-sm11">
            <label class="layui-form-label">角色权限</label>
            <div class="layui-input-block" >
                <div id="xtreeRes" style="max-height: 400px; border:1px solid; border-color:#D2D2D2!important;padding: 10px 0 25px 5px;"></div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text layui-col-md11 layui-col-sm11">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="description" readonly class="layui-textarea"></textarea>
            </div>
        </div>
    </form>
</fieldset>
</body>
<script src="../assets/layui/layui.js"></script>
<script src="../assets/layui-xtree/layui-xtree.js"></script>
<script>
    layui.config({
        base: '../js/'
    });
    layui.use(['jquery','form','common','tree'], function () {
        var form = layui.form,
            $ = layui.jquery,
            tree=layui.tree,
        common = layui.common;
        var id = common.getUrlParam("id");


            //获取用户信息
            $.ajax({
                url: "role/info",
                dataType: "json",
                data: { id: id },
                success: function (rtn) {
                    if (rtn && rtn.code===0) {
                        var data = rtn.data;
                        form.val('dataForm',{
                            roleId:data.roleId,
                            roleName:data.roleName,
                            description:data.description,
                        });
                    }
                }
            });
        $.ajax({
            url: "./common/roleResTree",
            dataType: "json",
            data: { roleId: id },
            success: function (rtn) {
                if (rtn && rtn.code===0) {
                    if(rtn.data){
                        for(var i =0;i<rtn.data.length;i++){
                            rtn.data[i].spread=true;
                        }
                    }
                    layui.tree({
                        elem: '#xtreeRes',
                        nodes:rtn.data
                    });
                }
            }
        });
    });
</script>
</html>